/**
 * Copyright 2009 The Apache Software Foundation
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package libMapReduce;

import java.util.ArrayList;
import java.util.Iterator;

import org.apache.hadoop.hbase.client.Scan;

/**
 * A collection of input tables and scanners to be used as the source data for a
 * mapper
 */
public class MultiTableInputCollection implements
    Iterable<MultiTableInputCollection.TableInputConf> {
  /**
   * An internal structure to hold table names + associated scanners
   */
  public class TableInputConf {
    private String tableName = null;
    private Scan scan = null;

    /**
     * The empty constructor
     */
    public TableInputConf() {
    }

    /**
     * 
     * @param tableName Input table name
     * @param scan A Scanner associated with this table
     */
    public TableInputConf(String tableName, Scan scan) {
      this.tableName = tableName;
      this.scan = scan;
    }

    /**
     * Returns the table name
     * 
     * @return The table name
     */
    public String getTableName() {
      return this.tableName;
    }

    /**
     * Sets the table name
     * 
     * @param tableName The table name to set
     */
    public void setTableName(String tableName) {
      this.tableName = tableName;
    }

    /**
     * Returns the scanner
     * 
     * @return The scanner
     */
    public Scan getScan() {
      return this.scan;
    }

    /**
     * Sets the scanner
     * 
     * @param tableName The scanner to set
     */
    public void setScan(Scan scan) {
      this.scan = scan;
    }
  }

  private ArrayList<TableInputConf> tables = new ArrayList<TableInputConf>();

  /**
   * Add new table and scanner pairs to the collection
   * 
   * @param tableName An input table name
   * @param scan An associated scanner
   */
  public void Add(String tableName, Scan scan) {
    TableInputConf tic = new TableInputConf(tableName, scan);
    tables.add(tic);
  }

  @Override
  public Iterator<TableInputConf> iterator() {
    return tables.iterator();
  }

  /**
   * Checks if the collection is empty
   * 
   * @return true if empty false otherwise
   */
  public boolean isEmpty() {
    return tables.isEmpty();
  }
}
